﻿Imports System
Imports NHibernate.Mapping.Attributes

<Serializable()> _
<[Class](Table:="SurvivorTeams")> _
Public Class TeamObj
    Private myTeamId As Integer
    Private myTeamName As String
    Private myTeamNameAbbrev As String
    Private mySurvivorYear As Integer
    Private myRegion As String
    Private mySeed As Integer
    Private myStillAlive As Boolean
    Private myRound1Result As Boolean?
    Private myRound2Result As Boolean?
    Private myRound3Result As Boolean?
    Private myRound4Result As Boolean?
    Private myRound5Result As Boolean?
    Private myRound6Result As Boolean?

    Public Enum TeamResult
        NotPlayed = 0
        Won = 1
        Loss = 2
    End Enum

    Public Overridable Property IsWinnerForRound(ByVal round As Integer) As Boolean
        Get
            Select Case round
                Case 1
                    If Round1Result IsNot Nothing AndAlso Round1Result = True Then Return True
                Case 2
                    If Round2Result IsNot Nothing AndAlso Round2Result = True Then Return True
                Case 3
                    If Round3Result IsNot Nothing AndAlso Round3Result = True Then Return True
                Case 4
                    If Round4Result IsNot Nothing AndAlso Round4Result = True Then Return True
                Case 5
                    If Round5Result IsNot Nothing AndAlso Round5Result = True Then Return True
                Case 6
                    If Round6Result IsNot Nothing AndAlso Round6Result = True Then Return True
            End Select

            Return False
        End Get
        Set(ByVal value As Boolean)
            Select Case round
                Case 1
                    Round1Result = value
                Case 2
                    Round2Result = value
                Case 3
                    Round3Result = value
                Case 4
                    Round4Result = value
                Case 5
                    Round5Result = value
                Case 6
                    Round6Result = value
            End Select
        End Set
    End Property


    Public Overridable Property IsLoserForRound(ByVal round As Integer) As Boolean
        Get
            Select Case round
                Case 1
                    If Round1Result IsNot Nothing AndAlso Round1Result = False Then Return True
                Case 2
                    If Round2Result IsNot Nothing AndAlso Round2Result = False Then Return True
                Case 3
                    If Round3Result IsNot Nothing AndAlso Round3Result = False Then Return True
                Case 4
                    If Round4Result IsNot Nothing AndAlso Round4Result = False Then Return True
                Case 5
                    If Round5Result IsNot Nothing AndAlso Round5Result = False Then Return True
                Case 6
                    If Round6Result IsNot Nothing AndAlso Round6Result = False Then Return True
            End Select

            Return False
        End Get
        Set(ByVal value As Boolean)
            Select Case round
                Case 1
                    Round1Result = value
                Case 2
                    Round2Result = value
                Case 3
                    Round3Result = value
                Case 4
                    Round4Result = value
                Case 5
                    Round5Result = value
                Case 6
                    Round6Result = value
            End Select
        End Set
    End Property

    Public Overridable Property HasNotPlayedForRound(ByVal round As Integer) As Boolean
        Get
            Select Case round
                Case 1
                    If Round1Result Is Nothing Then Return True
                Case 2
                    If Round2Result Is Nothing Then Return True
                Case 3
                    If Round3Result Is Nothing Then Return True
                Case 4
                    If Round4Result Is Nothing Then Return True
                Case 5
                    If Round5Result Is Nothing Then Return True
                Case 6
                    If Round6Result Is Nothing Then Return True
            End Select

            Return False
        End Get
        Set(ByVal value As Boolean)
            Select Case round
                Case 1
                    If value Then Round1Result = Nothing
                Case 2
                    If value Then Round2Result = Nothing
                Case 3
                    If value Then Round3Result = Nothing
                Case 4
                    If value Then Round4Result = Nothing
                Case 5
                    If value Then Round5Result = Nothing
                Case 6
                    If value Then Round6Result = Nothing
            End Select
        End Set
    End Property

    <Id(0, Name:="TeamId")> _
    <Generator(1, Class:="native")> _
    Public Overridable Property TeamId() As Integer
        Get
            Return myTeamId
        End Get
        Set(ByVal value As Integer)
            myTeamId = value
        End Set
    End Property

    <[Property]()> _
    Public Overridable Property TeamName() As String
        Get
            Return myTeamName
        End Get
        Set(ByVal value As String)
            myTeamName = value
        End Set
    End Property

    <[Property]()> _
    Public Overridable Property TeamNameAbbrev() As String
        Get
            Return myTeamNameAbbrev
        End Get
        Set(ByVal value As String)
            myTeamNameAbbrev = value
        End Set
    End Property

    <[Property]()> _
       Public Overridable Property SurvivorYear() As Integer
        Get
            Return mySurvivorYear
        End Get
        Set(ByVal value As Integer)
            mySurvivorYear = value
        End Set
    End Property

    <[Property]()> _
       Public Overridable Property Region() As String
        Get
            Return myRegion
        End Get
        Set(ByVal value As String)
            myRegion = value
        End Set
    End Property

    <[Property]()> _
       Public Overridable Property Seed() As Integer
        Get
            Return mySeed
        End Get
        Set(ByVal value As Integer)
            mySeed = value
        End Set
    End Property

    <[Property]()> _
       Public Overridable Property StillAlive() As Boolean
        Get
            Return myStillAlive
        End Get
        Set(ByVal value As Boolean)
            myStillAlive = value
        End Set
    End Property

    <[Property]()> _
       Public Overridable Property Round1Result() As Boolean?
        Get
            Return myRound1Result
        End Get
        Set(ByVal value As Boolean?)
            myRound1Result = value
        End Set
    End Property
    <[Property]()> _
       Public Overridable Property Round2Result() As Boolean?
        Get
            Return myRound2Result
        End Get
        Set(ByVal value As Boolean?)
            myRound2Result = value
        End Set
    End Property

    <[Property]()> _
       Public Overridable Property Round3Result() As Boolean?
        Get
            Return myRound3Result
        End Get
        Set(ByVal value As Boolean?)
            myRound3Result = value
        End Set
    End Property

    <[Property]()> _
       Public Overridable Property Round4Result() As Boolean?
        Get
            Return myRound4Result
        End Get
        Set(ByVal value As Boolean?)
            myRound4Result = value
        End Set
    End Property

    <[Property]()> _
       Public Overridable Property Round5Result() As Boolean?
        Get
            Return myRound5Result
        End Get
        Set(ByVal value As Boolean?)
            myRound5Result = value
        End Set
    End Property

    <[Property]()> _
       Public Overridable Property Round6Result() As Boolean?
        Get
            Return myRound6Result
        End Get
        Set(ByVal value As Boolean?)
            myRound6Result = value
        End Set
    End Property

    Public Overridable ReadOnly Property ResultForRound(ByVal curRound As Integer) As TeamResult
        Get
            Select Case curRound
                Case 1
                    If IsDBNull(Round1Result) OrElse Round1Result Is Nothing Then
                        Return TeamResult.NotPlayed
                    ElseIf Round1Result Then
                        Return TeamResult.Won
                    Else
                        Return TeamResult.Loss
                    End If
                Case 2
                    If IsDBNull(Round2Result) OrElse Round2Result Is Nothing Then
                        Return TeamResult.NotPlayed
                    ElseIf Round2Result Then
                        Return TeamResult.Won
                    Else
                        Return TeamResult.Loss
                    End If
                Case 3
                    If IsDBNull(Round3Result) OrElse Round3Result Is Nothing Then
                        Return TeamResult.NotPlayed
                    ElseIf Round3Result Then
                        Return TeamResult.Won
                    Else
                        Return TeamResult.Loss
                    End If
                Case 4
                    If IsDBNull(Round4Result) OrElse Round4Result Is Nothing Then
                        Return TeamResult.NotPlayed
                    ElseIf Round4Result Then
                        Return TeamResult.Won
                    Else
                        Return TeamResult.Loss
                    End If
                Case 5
                    If IsDBNull(Round5Result) OrElse Round5Result Is Nothing Then
                        Return TeamResult.NotPlayed
                    ElseIf Round5Result Then
                        Return TeamResult.Won
                    Else
                        Return TeamResult.Loss
                    End If
                Case 6
                    If IsDBNull(Round6Result) OrElse Round6Result Is Nothing Then
                        Return TeamResult.NotPlayed
                    ElseIf Round6Result Then
                        Return TeamResult.Won
                    Else
                        Return TeamResult.Loss
                    End If
            End Select
        End Get
    End Property

    Public Overridable ReadOnly Property DisplayMember()
        Get
            Return String.Format("{0}: {1} ({2})", Region, TeamName, Seed)
        End Get
    End Property

    Public Overridable ReadOnly Property DisplayMember2()
        Get
            Try
                Return String.Format("{0} ({1}{2})", TeamNameAbbrev, Region.Substring(0, 1), Seed)
            Catch ex As Exception
                Return TeamName
            End Try
        End Get
    End Property
End Class

